package com.cc.service.impl;

import com.cc.entity.Products;
import com.cc.mapper.ProductsMapper;
import com.cc.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ProductsServiceImpl implements ProductsService {

    @Autowired
    private ProductsMapper productsMapper;

    @Override
    @Transactional
    public int addProduct(Products product) {
        return productsMapper.insert(product);
    }

    @Override
    @Transactional
    public int deleteProduct(Integer productId) {
        return productsMapper.deleteByPrimaryKey(productId);
    }

    @Override
    @Transactional
    public int updateProduct(Products product) {
        return productsMapper.updateByPrimaryKey(product);
    }

    @Override
    public List<Products> getAllProducts() {
        return productsMapper.selectAll();
    }
}
